<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<form id="form1">
			用户名:<input type="text" name="username" id="input1" /><br />
			密码：<input type="text" name="password" id="input2" /><br />
			重复密码：<input type="text" name="r_password" id="input3" /><br />
			邮箱：<input type="text" name="e_mail" id="input4" /><br />
			电话号码：<input type="text" name="telephone_number" id="input5" /><br />
			<input type="submit"/>
			<input type="reset"/>
		</form>
		
		<script>
			
			input1.onfocus = function()
			{
				// 通过event.target得到当前触发事件的对象
				var obj = event.target;
				obj.style.backgroundColor = "#ff0000";
			}
			
			//onblur 获得焦点
			input1.onblur = function()
			{
				
				var obj = event.target;
				obj.style.backgroundColor = "#ffffff";
			}
			
			input5.onkeydown = function(e){
				console.log("键盘按下");
				console.log(e.key);
				console.log(e.keyCode);
				if(e.keyCode<48 || e.keyCode>57)
				{
					event.preventDefault()
				}
			}
			
			form1.onsubmit=function()
			{
				console.log("表单提交，检查表单内容是否正确")
				if(input2 == input3)
				{
					return true;
				}
				else
				{
					alert("重复密码错误")
					return false;
				}
			}
			
			form1.onreset = function()
			{
				console.log("表单重置")
			}
		</script>
		
	</body>
</html>
